package cn.sxw.ld.module.scrolling.controller;

import cn.sxw.ld.common.dto.R;
import cn.sxw.ld.module.scrolling.pojo.Scrolling;
import cn.sxw.ld.module.scrolling.service.ScrollingService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:ScrollingController
 * Package:cn.sjxy.graduation.controller
 * Description:
 *
 * @Date:2022/6/24 16:41
 * @Author:SXW
 */

@Slf4j
@RestController
@RequestMapping("/scrolling")
public class ScrollingController {

    @Autowired
    private ScrollingService scrollingService;

    @GetMapping("/page")
    public R<Page> page(int page, int pageSize, int type) {
        Page pageInfo = scrollingService.getPage(page, pageSize, type);
        return R.success(pageInfo);
    }

    @PostMapping("/add")
    public R<String> addScrolling(@RequestBody Scrolling scrolling) {
        scrollingService.save(scrolling);
        return R.success("添加成功");
    }

    @PostMapping("/edit")
    public R<String> editScrolling(@RequestBody Scrolling scrolling) {
        scrollingService.updateById(scrolling);
        return R.success("修改成功");
    }

    @DeleteMapping()
    public R<String> deleteScrolling(Long id) {
        scrollingService.removeById(id);
        return R.success("删除成功");
    }

    @GetMapping("/list")
    public R<List<Scrolling>> list(int type) {
        List<Scrolling> list = scrollingService.getlist(type);
        return R.success(list);
    }

    @GetMapping("/byId")
    public R<List<Scrolling>> getScrollingById(Long id) {
        List<Scrolling> list = scrollingService.getParagraph(id);
        if (list == null) {
            return R.error("输入不是段落ID，请检查~");
        }
        return R.success(list);
    }

}

